<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>文件上传</title>
    <!-- Import Vue 2 -->
    <!-- Import Element UI CSS & JS -->
    <link
      rel="stylesheet"
      href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"
    />
    <script src="https://unpkg.com/vue@2/dist/vue.js"></script>
    <!-- import JavaScript -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <!-- Import Axios -->
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      body {
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          Helvetica, Arial, sans-serif;
        margin: 0;
        padding: 20px;
        background-color: #f8fafc;
      }
      h1 {
        text-align: center;
        color: #1e293b;
      }
      .image-container {
        display: flex;
        flex-wrap: wrap;
        gap: 20;
        margin-left: 15px;
        gap: 15px;
        padding: 15px 0;
        -webkit-overflow-scrolling: touch;
      }
      .image-container::-webkit-scrollbar {
        display: none;
      }
      .image-item {
        height: 200px;
        border-radius: 8px;
        flex-wrap: wrap;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        transition: transform 0.3s ease, box-shadow 0.3s ease;
        flex-shrink: 0;
      }
      .image-item:hover {
        transform: translateY(-5px);
        box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
      }
      .image-item img {
        height: 200px;
        width: auto;
        object-fit: cover;
      }
      .btn-container {
        text-align: center;
        margin-top: 20px;
      }
      /* 渐变遮罩 */
      .mask-left,
      .mask-right {
        position: absolute;
        top: 0;
        height: 100%;
        width: 40px;
        pointer-events: none;
      }
      .mask-left {
        left: 0;
        background: linear-gradient(to right, #f8fafc, transparent);
      }
      .mask-right {
        right: 0;
        background: linear-gradient(to left, #f8fafc, transparent);
      }
      .relative-container {
        position: relative;
      }
      .upload-container {
        margin: 20px;
      }
      .chengfen {
        display: flex;
        align-items: center;
        margin: 20px 10px;
        font-size: 20px;
        font-weight: 600;
        color: #333;
      }
      .chengfen span {
        margin-left: 30px;
      }
      .chengfen a {
        margin-left: 30px;
      }
      .paste-hint {
        text-align: center;
        margin: 10px 0;
        color: #666;
        font-size: 14px;
      }
      .paste-area {
        border: 2px dashed #dcdfe6;
        border-radius: 6px;
        padding: 20px;
        text-align: center;
        margin: 20px;
        background-color: #f5f7fa;
        transition: all 0.3s;
      }
      .paste-area.active {
        border-color: #409eff;
        background-color: #ecf5ff;
      }
      h2 {
        text-align: center;
        margin-bottom: 20px;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <el-input
        type="textarea"
        :autosize="{ minRows: 10, maxRows: 15}"
        placeholder="请输入内容"
        v-model="imgText"
      >
      </el-input>
      <!-- <div
        class="image-container"
        id="imageContainer"
        v-if="imgText.length > 0"
      >
        <div class="image-item" v-for="(imgUrl, index) in imgList" :key="index">
          <img :src="imgUrl" :alt="'示例图片' + index" />
        </div>
      </div> -->

      <el-button @click="handleClickBtn" style="margin-bottom: 20px"
        >筛选</el-button
      >

      <div style="display: flex; align-items: center">
        <div v-if="imgUrl" style="width: 400px">
          <img :src="imgUrl" width="300px" height="auto" />
        </div>
        <!-- <div v-if="imgUrl">图片地址：{{ imgUrl }}</div> -->
        <div style="width: 502px; margin-left: 20px">
          <h2>尺码表</h2>
          <el-table :data="tableData" border style="width: 100%">
            <el-table-column prop="size" label="尺寸" width="100">
            </el-table-column>
            <el-table-column prop="length" label="衣长" width="100">
            </el-table-column>
            <el-table-column prop="bust" label="胸围" width="100">
            </el-table-column>
            <el-table-column prop="shoulder" label="肩宽" width="100">
            </el-table-column>
            <el-table-column prop="sleeve" label="袖长" width="100">
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div v-if="imgUrl">图片地址：{{ imgUrl }}</div>
    </div>

    <script>
      new Vue({
        el: "#app",
        data() {
          return {
            imgText: "",
            isPasteActive: false,
            imgUrl: "",
            tableData: [],
          };
        },
        computed: {
          imgList: function () {
            return this.imgText.split(",") || [];
          },
        },
        mounted() {
          // 全局监听粘贴事件
          document.addEventListener("paste", this.handleDocumentPaste);
        },
        beforeDestroy() {
          // 移除事件监听
          document.removeEventListener("paste", this.handleDocumentPaste);
        },
        methods: {
          focusPasteArea() {
            this.$refs.pasteArea.focus();
          },
          handleClickBtn() {
            console.log("this.imgList", this.imgList);
            console.log("开始请求");
            // 47.97.167.190
            fetch("http://47.97.167.190:5000/api/filter", {
              method: "POST",
              headers: {
                "Content-Type": "application/json",
              },
              body: JSON.stringify({
                imgList: this.imgList,
              }),
            })
              .then((response) => response.json())
              .then((data) => {
                console.log(data);
                this.imgUrl = data.imgUrl;
                this.tableData = data.result;
              })
              .catch((error) => {
                console.error("Request failed:", error);
              });
          },
        },
      });
    </script>
  </body>
</html>
